<?php

// Checkt ob die übergebene E-Mail Adresse gültig ist
// ToDo: DO!
function checkEmail($email) {
	if($email == "undefined") return false;
	// syntax checken
	$email = trim($email);
	$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]';   
	$domain = '([a-z]([-a-z0-9]*[a-z0-9]+)?)';
	$regex = '^'.$atom.'+'.'(\.' . $atom . '+)*'.'@'.'(' . $domain . '{1,63}\.)+'.$domain . '{2,63}'.'$';
	return true; //eregi($regex, $email);
}

// Bislang in Arbeit
function checkUrl($url) {
	if($url == "undefined") return false;
	$url = trim($url);	
	$domain = "([[:alpha:]][-[:alnum:]]*[[:alnum:]])(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])+";
    $dir = "(/[[:alpha:]][-[:alnum:]]*[[:alnum:]])*";
    $page = "(/[[:alpha:]][-[:alnum:]]*\.[[:alpha:]]{3,5})?";
    $getstring = "(\?([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+)(&([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+))*)?";
    $pattern = "^".$domain.$dir.$page.$getstring."$";
    // return eregi($pattern, $url);
	return true;
}	

function checkNum($num,$use,$size) {
	if($num == "undefined") return false;
	if        (!is_numeric($num))                   return false;
	if        ($use == "min")  { if ($num <  $size) return false; }
	else if   ($use == "max")  { if ($num >  $size) return false; }
	else if   ($use == "genau"){ if ($num != $size) return false; }
	return true;
}

function checkBool($bool) {
	if($bool == "undefined") return false;
	if ($bool == 0)       $bool = true;
	if ($bool == "TRUE")  $bool = true;
	if ($bool == "true")  $bool = true;
	if ($bool == 1)       $bool = false;
	if ($bool == "FALSE") $bool = false;
	if ($bool == "false") $bool = false;
	if (!is_bool($bool))   return false;
	return true;
}

function checkString($str,$use,$size) {
	if        ($str == "undefined") return false;
	if        (!is_string($str))    return false;
	if        (strlen($str) <  1)   return false;
	if        ($use == "min"   ) { if (strlen($str) <  $size) return false; }
	else if   ($use == "max"   ) { if (strlen($str) >  $size) return false; }
	else if   ($use == "genau" ) { if (strlen($str) != $size) return false; }		
	return true;
}

function checkSpaces($str) {
	if (strpos($str, " ") > -1) return false;
	return true;
}


function checkEditor($editor) {
	if($editor == "undefined") return false;
	if ($editor == "LFBB")    return true;
	if ($editor == "WYSIWYG") return true;
	return false;
}

function checkIstWertInArray($string,$array) {
	if($string == "undefined") return false;
	foreach ($array as $wert) {
		if ($wert == $string) return true;
	}
	return false;
}
?>